<template>
	<view class="goshop-search-container">
		<view class="goshop-search-wrap">
			<view class="row-cen">
				<view class="iconfont iconfont-left_arrow icon-bg-color" @click="back"></view>
			</view>
			<u-search class="u-m-l-10" v-model="tempKeyword" @custom="getGoodPage" :actionText="searchText" @click="getGoodPage" @search="getGoodPage" :placeholder="placeholderText"></u-search>
		</view>
		<view class="goshop-search-good">
			<!-- 空白页 -->
			<u-empty v-if="isEmpty === true && goodDataList.length === 0" :text="emptyText" mode="list"></u-empty>
			<goshop-good-waterfalls-flow ref="waterfallsFlowRef" @imageClick="onGoodClick" @wapperClick="onGoodClick" :data="goodDataList"></goshop-good-waterfalls-flow>
			<u-loadmore
					v-if="goodDataList.length > 0"
					:status="loadStatus" 
					:loading-text="loadingText" 
					:loadmore-text="loadmoreText" 
					:nomore-text="nomoreText" 
					loadingIcon="semicircle"
					@loadmore="getGoodPage"
					style="margin-bottom: 60px;"
				/>
		</view>
	</view>
</template>

<script>
	import {goodPage} from '@/common/http.api.js'
	export default {
		data() {
			return {
				//加载更多标志
				loadMoreFlag:false,
				isEmpty:false,
				goodDataList: [],
				searchText:'',
				emptyText:'',
				placeholderText:'',
				loadStatus: 'loadmore',
				loadingText: '',
				loadmoreText: '',
				nomoreText: '',
				tempKeyword:'',
				params: {
					pageNo: 1,
					search:'',
					pageSize: 10,
				},
			};
		},
		onShow(){
		   this.refresh();	
		},
		methods:{
			refresh(){
				this.emptyText = this.$t('common.empty.text');
				this.searchText = this.$t('search.search.text');
				this.placeholderText = this.$t('search.placeholder.text');
				this.loadingText = this.$t('common.loading.text');
				this.loadmoreText = this.$t('common.loadmore.text');
				this.nomoreText = this.$t('common.nomore.text');
			},
			back(){
				uni.navigateBack({
					delta: 1
				});
			},
			onGoodClick(item){
				uni.navigateTo({
					url: 'pages/common/good/info?id='+item.id
				});
			},
			getGoodPage(){
				this.loadStatus = 'loading';
				debugger
				if(this.params.search != this.tempKeyword){
					this.goodDataList = [];
					this.$refs.waterfallsFlowRef.refresh();
				}
				this.params.search = this.tempKeyword;
				goodPage(this.params).then((res)=>{
					uni.stopPullDownRefresh()
					if(res.code === 0){
					  if(res.data.list.length === 0){
						this.isEmpty = true;
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  }else if (res.data.list.length < 10) {
						this.loadStatus = 'nomore'
						this.loadMoreFlag = false;
					  } else {
						this.params.pageNo++;
						this.loadStatus = 'loading'
						this.loadMoreFlag = true;
					  }
					  if (this.params.pageNo > 1) {
						this.goodDataList = this.goodDataList.concat(res.data.list);
					  } else {
						this.goodDataList = res.data.list;
					  }
					}
				  }).catch(error=>{
					console.error(error)
				  })
			},
		}
	}
</script>

<style lang="scss">
.goshop-search-container{
	.goshop-search-wrap{
		background-color: $goshop-color-primary;
		display: flex;
		padding: 20rpx;
	}
	.goshop-search-good{
		padding: 20rpx;
	}
}
</style>
